<?php
/**
 * Created by Engineer CuiLiwu.
 * Project: deal.
 * Date: 2018/5/25-8:28
 * License Hangzhou orce Technology Co., Ltd. Copyright © 2018
 */

namespace App\Http\Controllers\Web\Member\Buyer;

use App\Http\Controllers\Web\BaseController;
use Illuminate\Http\Request;


class BuyerIndexController extends BaseController
{
    protected $api_url = [
        // 订单列表
        'user_order' => ['get', 'buyer/orders/buyer_index'],
        // 订单计数
        'user_count' => ['get', 'buyer/orders/count'],
        // 个人信息
        'user_info'  => ['get', 'member/member/%d'],
        // 个人配单
        'user_match' => ['get', 'buyer/items/buyer_index'],
        // 浏览记录
        'user_history'=> ['get', 'product/get-history'],
    ];

    protected $request;
    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function index()
    {
        $data = [];
        //参数部分
        $params = [
            'searchJoin' => 'and',
            'with' => 'orderProducts;shop',
            'orderBy'=>'id',
            'sortedBy'=>'desc',
        ];

        //请求部分 获取订单
        $ret = http_web($this->api_url['user_order'])->send($params);
        $data['order'] = isset($ret['data'][0])?$ret['data'][0]:null;
    
        // 获取个人信息
        $user_info = http_web($this->api_url['user_info'],[session('user_id')])->send();
        $data['info'] =$user_info['data']['data'];

        // 获取计数信息
        $user_count = http_web($this->api_url['user_count'])->send();
        $data['count'] = $user_count['data'];

        // 获取配单信息
        $params = [
            'orderBy'=>'id',
            'sortedBy'=>'desc',
        ];
        $items = http_web($this->api_url['user_match'])->send($params);
        $items = $items['data'];
        foreach($items as $k=>$v){
            $items[$k]['items_information']['quote_contain']=\GuzzleHttp\json_decode($v['items_information']['quote_contain']);
        }
        $data['items']=isset($items[0])?$items[0]:null;
        // 获取浏览记录
        return view('web.user.buyer.buyer_index', $data);
    }
}